import React, { Component } from 'react'
/**
 * 查询组件
 * @export
 * @class StudentSearch
 * @extends {Component}
 */
export default class StudentSearch extends Component {
    constructor(props) {
        super(props)
        console.log('props', props);
        this.state = Object.assign({}, { key: "", sex: -1 }, props.defaultValue || {})
    }

    static defaultProps = {
        onSearch: () => { }
    }

    radioChange = e => this.setState({ sex: +e.target.value })

    search = () => this.props.onSearch(this.state)

    render() {
        return (
            <div>
                关键字：
                <input type="text" value={this.state.key} onChange={e => { this.setState({ key: e.target.value }) }} />
                性别：
                <label><input onChange={this.radioChange} checked={this.state.sex === -1} type="radio" name="sex" value={-1} />不限</label>
                <label><input onChange={this.radioChange} checked={this.state.sex === 0} type="radio" name="sex" value={0} />男</label>
                <label><input onChange={this.radioChange} checked={this.state.sex === 1} type="radio" name="sex" value={1} />女</label>
                <button onClick={this.search}>查询</button>
            </div>
        )
    }
}
